package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.dao.StudentDAO;
import com.web.dao.impl.StudentDAOimpl;
import com.web.entity.ResponseResult;
import com.web.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/findStudents")
//查询所有
public class FindAll extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求编码
        req.setCharacterEncoding("UTF-8");
        //设置响应编码
        resp.setCharacterEncoding("UTF-8");
        //设置响应类型
        resp.setContentType("application/json;charset=UTF-8");

        StudentDAO studentDAO = new StudentDAOimpl();
        List<Student> students = studentDAO.selectAllStudents();
        ResponseResult result = new ResponseResult(200, students, "ok");
        String str = JSON.toJSONString(result);
        resp.getWriter().write(str);
        System.out.println(str);











    }

}
